package com.xb.myspring.config;

import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.Map;

/**
 * 1ApplicationContextInitializer
 * 整个spring容器还没被初始化之前，class还没被类加载器加载的时机，进行动态字节码注入等操作。
 * 配置：
 *      1、启动类中用springApplication.addInitializers(new TestApplicationContextInitializer())
 *      2、context.initializer.classes=com.example.demo.TestApplicationContextInitializer
 *      3、Spring SPI扩展，在spring.factories中加入org.springframework.context.ApplicationContextInitializer=com.example.demo.TestApplicationContextInitializer
 */
public class TestApplicationContextInitializer implements ApplicationContextInitializer {
    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
        Map<String, Object> systemProperties = applicationContext.getEnvironment().getSystemProperties();
        System.out.println("SpringExtend-1ApplicationContextInitializer");
        System.out.println("---------------start------------------");
        systemProperties.forEach((key,value)->{
            System.out.println("key:"+key+",****************value:"+value);
        });
        System.out.println("---------------end------------------");
    }
}      